package cn.chengpengper.transfer.ui;

import cn.chengpengper.transfer.listener.TranslatorButtonActionListener;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;

import cn.chengpengper.transfer.provider.TranslatorTextProvider;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.ui.GotItTooltip;
import com.intellij.util.textCompletion.TextFieldWithCompletion;

public class TranslatorWindow {
    private JTabbedPane tabbedPane1;
    private JPanel mainPanel;
    private JPanel translatorPanel;
    private JPanel notePanel;
    private JTable noteTable;
    private JComboBox comboBox1;
    private TextFieldWithCompletion originalTextArea;
    private JComboBox comboBox2;
    private JTextArea translateTextArea;
    private JButton translateButton;

    public TranslatorWindow() {
        // 下拉框添加下拉选项
        comboBox1.addItem("英文");
        comboBox1.addItem("中文");

        comboBox2.addItem("中文");
        comboBox2.addItem("英文");

        String[] header = {"原文","译文"};
        DefaultTableModel tableModel = new DefaultTableModel(null,header);
        noteTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
        noteTable.setModel(tableModel);

        translateButton.addActionListener(new TranslatorButtonActionListener(this));

        tabbedPane1.addChangeListener(e->{
            JTabbedPane tab = (JTabbedPane) e.getSource();
            if(tab.getSelectedIndex() == 1){
                return;
            }
            new GotItTooltip("got.it.id","翻译插件",ProjectManager.getInstance().getDefaultProject())
                    .withShowCount(100)
                    .withHeader("输入文本，点击翻译按钮即可完成翻译")
                    .show(translateButton,GotItTooltip.BOTTOM_MIDDLE);
        });
    }

    public JComboBox getComboBox2() {
        return comboBox2;
    }

    public JTabbedPane getTabbedPane1() {
        return tabbedPane1;
    }

    public JPanel getMainPanel() {
        return mainPanel;
    }

    public JPanel getTranslatorPanel() {
        return translatorPanel;
    }

    public JPanel getNotePanel() {
        return notePanel;
    }

    public JTable getNoteTable() {
        return noteTable;
    }

    public JComboBox getComboBox1() {
        return comboBox1;
    }

    public TextFieldWithCompletion getOriginalTextArea() {
        return originalTextArea;
    }

    public JTextArea getTranslateTextArea() {
        return translateTextArea;
    }

    public JButton getTranslateButton() {
        return translateButton;
    }

    private void createUIComponents() {
        originalTextArea = new TextFieldWithCompletion(ProjectManager.getInstance().getDefaultProject(),
                new TranslatorTextProvider(), "", true, true, true, true);
    }
}
